<?php
  require_once('conn.php');
  $sid = isset($_GET["sid"]) ? $_GET["sid"] : "";
  $action = isset($_GET["act"]) ? $_GET["act"] : "";
  if(!is_numeric($sid)){
	  mysql_close($conn);
	  echo "<script language='javascript' type='text/javascript'>alert('主题参数sid只能是数字');history.back(1);</script>";
  }
  if($action=="save"){	 
     $subject=$_POST["subject"];
	 $qx=$_POST["qx"];
	 $query=mysql_query("select * from xh_subject where id<>".$sid." and subject='".$subject."'",$conn);
	 if(mysql_num_rows($query)>0){		 
		 mysql_free_result($query);
		 mysql_close($conn);
         errormsg("该主题已经存在!");
		 exit();
	 }
	 mysql_free_result($query);	 
	 $cmd="update `xh_subject` set `subject`='".$subject."',qx='".$qx."' where id=".$sid;
	 $query=mysql_query($cmd,$conn);
	 mysql_close($conn);
	 successmsg("主题修改成功!");
	 exit();
	 
 } 
 $query=mysql_query("select * from xh_subject where id=".$sid,$conn);
 $subject="";
 $qx="";
 if($row=mysql_fetch_array($query)){
	 $subject=$row["subject"];
	 $qx=$row["qx"];	 
 }else{
	 mysql_close($conn);
	 errormsg("该主题不存在!");
	 exit();
 }
 mysql_free_result($query); 
?>
<html>
<head>
<?php
     head();
	 check();	 
?>
<title>后台管理中心</title>
</head>
<script language="javascript" type="text/javascript">
function check(){
	if(form1.subject.value==""){
		lblsubject.innerHTML = "投票主题不能为空！";
		form1.subject.focus();
		return false;}
	else{
		lblsubject.innerHTML = "";}	
	if(form1.dt.value==""){
		lblqx.innerHTML = "时间不能为空！";
		form1.dt.focus();
		return false;
	}else{
		lblqx.innerHTML="";
	}	
	return true;
}
</script>
<body>
<table border="0" cellpadding="1" cellspacing="2" width="100%" id="table1" bgcolor="#E1F0FF">
  <tr>
    <td>
		<table width="100%" id="table2" cellspacing="1">
	     <tr>
          <td id="TableTitle1"> 修改投票主题-&gt;</td>
		 </tr>
	   </table>
	 </td>
  </tr>
  <tr>
    <td><table border="1" cellpadding="4" cellspacing="0" width="100%" id="table2" bordercolor="#BFDFFF">
        <form action="?act=save&sid=<?php echo $sid;?>" method="post" name="form1" onSubmit="return check()">
          <tr>
            <td width="20%" align="right">投票主题名称：</td>
            <td><input type="text" name="subject" size="25" value="<?php echo $subject;?>">
              <label id="lblsubject"></label></td>
          </tr>          
		  <tr>
		  <td width="20%" align="right">到期时间：</td>
		  <td >
		  <input type="text" name="qx" value="<?php echo $qx;?>" size="18"><label id="lblqx"></label><font color="red">时间格式yyyy-mm-dd hh:mm:ss</font>
		  </td>
		  </tr>
          <tr>
            <td colspan="2" align="center" bgcolor="#BFDFFF"><input class="btn" type="submit" name="submit" value=" 修 改 "></td>
          </tr>
        </form>
      </table></td>
  </tr>
</table>
</body>
</html>
<?php mysql_close($conn);?>